package org.kealinghornets.jchuah.buttons;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;


public class Level2Activity extends MainActivity {


    public void checkVictory() {
        View LeftStar = findViewById(R.id.LeftStar);
        View MiddleStar = findViewById(R.id.MiddleStar);
        View RightStar = findViewById(R.id.RightStar);
        if (LeftStar.getVisibility() == View.INVISIBLE && MiddleStar.getVisibility() == View.INVISIBLE && RightStar.getVisibility() == View.INVISIBLE) {
            Toast.makeText(this, "You have won a somewhat useful game! This is about as much as your worthless mind can handle. Give up now.", Toast.LENGTH_LONG).show();
            startActivity (new Intent(this, Level3Activity.class));
        }
    }


    public void makeVisible (int id) {
        View Star;

        Star = findViewById(id);

        if (Star.getVisibility()==View.INVISIBLE) {
            Star.setVisibility(View.VISIBLE);
        }else{
            Star.setVisibility(View.VISIBLE);
        }
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_level2);
    }

    public void onLoserButtonPush(View view) {
        startActivity(new Intent(this, MainActivity.class));
        Toast.makeText(this, "Nice try.", Toast.LENGTH_SHORT).show();
    }

    public void onFirstButtonPush (View view){
        Log.d("Yourface", "First button.");
        Toast.makeText(this, "Ya done pushed the button.", Toast.LENGTH_SHORT).show();
        toggleVisibility (R.id.LeftStar);
        toggleVisibility(R.id.RightStar);
        checkVictory();
    }

    public void onSecondButtonPush (View view){
        Log.d("Yourface", "Second button.");
        Toast.makeText(this, "Don't be pushing my buttons.", Toast.LENGTH_SHORT).show();
        toggleVisibility(R.id.LeftStar);
        toggleVisibility(R.id.MiddleStar);
        checkVictory();
    }

    public void onThirdButtonPush (View view) {
        Log.d("Yourface", "Third button.");
        Toast.makeText(this, "I said don't push them!.", Toast.LENGTH_SHORT).show();
        makeVisible(R.id.LeftStar);
        checkVictory();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_level2, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
